/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.opgea.appstreet.service.impl;

import com.opgea.appstreet.dao.CategoryDAO;
import com.opgea.appstreet.dao.CityDAO;
import com.opgea.appstreet.dao.CountryDAO;
import com.opgea.appstreet.dao.SubCategoryDAO;
import com.opgea.appstreet.domain.entities.Category;
import com.opgea.appstreet.domain.entities.City;
import com.opgea.appstreet.domain.entities.Country;
import com.opgea.appstreet.domain.entities.SubCategory;
import com.opgea.appstreet.domain.model.SimpleModel;
import com.opgea.appstreet.service.UtilService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author Ramesh
 */
@Service
public class UtilServiceImpl implements UtilService{

    
    @Autowired
    private CountryDAO countryDAO;
    @Autowired
    private CityDAO cityDAO;
    @Autowired
    private CategoryDAO categoryDAO;
    @Autowired
    private SubCategoryDAO subCategoryDAO;
    
    @Override
    public List<SimpleModel> getAllCountries() {
        List<Country> countries = countryDAO.findAll();
        List<SimpleModel> countryList = new ArrayList<SimpleModel>();
        for(Country country : countries){
            SimpleModel model = new SimpleModel();
            model.setId(new Long(country.getId()));
            model.setValue(country.getName());
            countryList.add(model);
        }
        return countryList;
    }

    @Override
    public List<SimpleModel> getAllCities() {
        List<City> cities = cityDAO.findAll();
        List<SimpleModel> cityList = new ArrayList<SimpleModel>();
        for(City city : cities){
            SimpleModel model = new SimpleModel();
            model.setId(new Long(city.getId()));
            model.setValue(city.getName());
            cityList.add(model);
        }
        return cityList;
    }

    @Override
    public List<SimpleModel> getCitiesByCountry(Long countryId) {
        List<City> cities = cityDAO.findAllByCountry(countryId);
        List<SimpleModel> cityList = new ArrayList<SimpleModel>();
        for(City city : cities){
            SimpleModel model = new SimpleModel();
            model.setId(new Long(city.getId()));
            model.setValue(city.getName());
            cityList.add(model);
        }
        return cityList;
    }

    @Override
    public List<SimpleModel> getAllCategories() {
        List<Category> categories = categoryDAO.findAll();
        List<SimpleModel> categoryList = new ArrayList<SimpleModel>();
        for(Category category: categories){
            SimpleModel model = new SimpleModel();
            model.setId(new Long(category.getId()));
            model.setValue(category.getName());
            categoryList.add(model);
        }
        return categoryList;
    }

    @Override
    public List<SimpleModel> getAllSubCategories() {
        List<SubCategory> subCategories = subCategoryDAO.findAll();
        List<SimpleModel> subCategoryList = new ArrayList<SimpleModel>();
        for(SubCategory subCategory: subCategories){
            SimpleModel model = new SimpleModel();
            model.setId(new Long(subCategory.getId()));
            model.setValue(subCategory.getName());
            subCategoryList.add(model);
        }
        return subCategoryList;
    }

    @Override
    public List<SimpleModel> getSubCategoriesByCategory(Long categoryId) {
        List<SubCategory> subCategories = subCategoryDAO.findByCategory(categoryId);
        List<SimpleModel> subCategoryList = new ArrayList<SimpleModel>();
        for(SubCategory subCategory: subCategories){
            SimpleModel model = new SimpleModel();
            model.setId(new Long(subCategory.getId()));
            model.setValue(subCategory.getName());
            subCategoryList.add(model);
        }
        return subCategoryList;
    }
    
}
